package thread.threaddemo;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/05/21:44
 * @Description:对比用户线程和守护线程的区别
 */
public class ThreadDemoByDaemon2 {
    public static void main(String[] args) {
        userThread();
       // daemonThread();
        //Thread.sleep(500);
    }

    /**
     * 守护线程
     */
//    private static void daemonThread() {
//        Thread thread=new Thread(()->{
//            for (int i = 0; i < 10; i++) {
//                System.out.println("执行:"+i);
//                try {
//                    Thread.sleep(500);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//        thread.setDaemon(true);
//        thread.start();
//    }

    /**
     * 用户线程
     */
    private static void userThread() {
        Thread thread=new Thread(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println("执行:"+i);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
    }
}
